#!/bin/sh
set -e

if [ "$1" = "install" ] || [ "$1" = "upgrade" ]; then
	LIST="/sbin/fsck /sbin/fsck_apfs /sbin/fsck_exfat /sbin/fsck_hfs /sbin/fsck_msdos /sbin/launchd /sbin/mount
	/sbin/mount_apfs /sbin/mount_hfs /sbin/newfs_apfs /sbin/newfs_hfs /sbin/pfctl /usr/sbin/BTAvrcp
	/usr/sbin/BTLEServer /usr/sbin/BTMap /usr/sbin/BTPbap /usr/sbin/BlueTool
	/usr/sbin/WirelessRadioManagerd /usr/sbin/absd /usr/sbin/addNetworkInterface /usr/sbin/aslmanager
	/usr/sbin/bluetoothd /usr/sbin/cfprefsd /usr/sbin/distnoted /usr/sbin/filecoordinationd
	/usr/sbin/ioreg /usr/sbin/ipconfig /usr/sbin/mDNSResponder /usr/sbin/mDNSResponderHelper /usr/sbin/mediaserverd
	/usr/sbin/notifyd /usr/sbin/nvram /usr/sbin/pppd /usr/sbin/racoon /usr/sbin/rtadvd /usr/sbin/scutil
	/usr/sbin/spindump /usr/sbin/syslogd /usr/sbin/wifid /sbin/umount"
	for bin in ${LIST}; do
		if [ -f "${bin}" ]; then
			cp -af "${bin}" "${bin}".sbin
		elif [ ! -d "${bin}" ]; then
			echo "Expected firmware file \"${bin}\" missing"
			exit 1;
		fi;
	done
fi
